unit RFatura4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RLReport, RLParser, RLPreviewForm;

type
  TFormRFatura4 = class(TForm)
    RLReport1: TRLReport;
    RLBand1: TRLBand;
    RLGroup1: TRLGroup;
    RLBand2: TRLBand;
    RLLabel1: TRLLabel;
    RLLabel2: TRLLabel;
    RLLabel3: TRLLabel;
    RLLabel5: TRLLabel;
    RLLabel6: TRLLabel;
    RLLabel4: TRLLabel;
    RLDBText10: TRLDBText;
    RLImage1: TRLImage;
    RLDBText31: TRLDBText;
    RLDBText32: TRLDBText;
    RLLabel33: TRLLabel;
    RLLabel34: TRLLabel;
    RLExpressionParser1: TRLExpressionParser;
    RLBand7: TRLBand;
    RLLabel8: TRLLabel;
    RLLabel11: TRLLabel;
    RLLabel12: TRLLabel;
    RLLabel13: TRLLabel;
    RLLabel14: TRLLabel;
    RLDBText9: TRLDBText;
    RLLabel15: TRLLabel;
    RLDBText12: TRLDBText;
    RLLabel17: TRLLabel;
    RLBand8: TRLBand;
    RLLabel16: TRLLabel;
    RLLabel18: TRLLabel;
    RLDBText11: TRLDBText;
    RLDBText13: TRLDBText;
    RLDBText15: TRLDBText;
    RLDBText16: TRLDBText;
    RLDBText17: TRLDBText;
    RLDBText18: TRLDBText;
    RLDBText19: TRLDBText;
    RLBand6: TRLBand;
    RLLabel20: TRLLabel;
    RLDBResult2: TRLDBResult;
    RLDBText20: TRLDBText;
    RLLabel21: TRLLabel;
    RLLabel22: TRLLabel;
    RLDBText21: TRLDBText;
    RLLabel9: TRLLabel;
    RLLabel23: TRLLabel;
    RLDBResult4: TRLDBResult;
    RLLabel26: TRLLabel;
    RLLabel28: TRLLabel;
    RLLabel29: TRLLabel;
    RLLabel31: TRLLabel;
    RLLabel24: TRLLabel;
    RLLabel27: TRLLabel;
    RLLabel32: TRLLabel;
    RLLabel35: TRLLabel;
    RLLabel36: TRLLabel;
    RLLabel25: TRLLabel;
    RLDBResult1: TRLDBResult;
    RLDBText14: TRLDBText;
    RLLabel19: TRLLabel;
    RLGroup2: TRLGroup;
    RLBand3: TRLBand;
    RLGroup3: TRLGroup;
    RLBand4: TRLBand;
    RLDBText2: TRLDBText;
    RLLabel10: TRLLabel;
    RLBand5: TRLBand;
    RLDBText1: TRLDBText;
    RLDBText4: TRLDBText;
    RLDBText5: TRLDBText;
    RLDBText6: TRLDBText;
    RLDBText7: TRLDBText;
    RLDBText22: TRLDBText;
    RLDBText8: TRLDBText;
    RLDBText23: TRLDBText;
    RLDBText24: TRLDBText;
    RLDBText25: TRLDBText;
    RLDBText26: TRLDBText;
    RLLabel7: TRLLabel;
    RLLabel30: TRLLabel;
    RLDBText3: TRLDBText;
    RLDBText27: TRLDBText;
    RLBand9: TRLBand;
    RLDBResult3: TRLDBResult;
    RLLabel37: TRLLabel;
    procedure RLBand1BeforePrint(Sender: TObject; var PrintIt: Boolean);
    procedure RLDBText9BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLBand2BeforePrint(Sender: TObject; var PrintIt: Boolean);
    procedure RLLabel20BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLLabel25BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLLabel26BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLBand4BeforePrint(Sender: TObject; var PrintIt: Boolean);
    procedure RLReport1BeforePrint(Sender: TObject; var PrintIt: Boolean);
    procedure RLLabel27BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLDBText22BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLDBText26BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLDBResult1BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLDBResult4BeforePrint(Sender: TObject; var Text: String;
      var PrintIt: Boolean);
    procedure RLDBText23BeforePrint(Sender: TObject; var Text: string;
      var PrintIt: Boolean);
  private
    { Private declarations }
    Obs : String;
    CodFatura, QuantRast, QuantTele, TotalTempo : Integer;
    TotalPeso : Real;

  public
    { Public declarations }
  end;

var
  FormRFatura4: TFormRFatura4;

implementation

uses DMR, Geral, DMS, Math, ZAbstractRODataset, DB;

{$R *.dfm}

procedure TFormRFatura4.RLBand1BeforePrint(Sender: TObject;
  var PrintIt: Boolean);
begin
    DMSr.dsEmpresaProp.DataSet.Open;
    if (GetParametro('LOGO') <> '') and ((pos('BMP',UpperCase(GetParametro('LOGO'))) > 0) or (pos('JPG',UpperCase(GetParametro('LOGO'))) > 0))then
        RLImage1.Picture.LoadFromFile(GetParametro('LOGO'));
end;

procedure TFormRFatura4.RLDBText9BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := Text + ', '+ getcampoquery('cidade','(nome ||'+chr(39)+'-'+chr(39)+'|| uf) as cidade', 'codcidade', DMSr.dsEmpresaProp.dataset.fieldbyname('CODCIDADE').asstring);
end;

procedure TFormRFatura4.RLBand2BeforePrint(Sender: TObject;
  var PrintIt: Boolean);
begin
    Obs := dmrel.QueryRFatura.FieldByName('OBS1').AsString;
    CodFatura := dmrel.QueryRFatura.FieldByName('CODFATURA').AsInteger;
end;

procedure TFormRFatura4.RLLabel20BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := text +' '+ obs;
end;

procedure TFormRFatura4.RLLabel25BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := IntToStr(QuantRast+QuantTele);
end;

procedure TFormRFatura4.RLLabel26BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := IntToStr(QuantTele);
end;

procedure TFormRFatura4.RLBand4BeforePrint(Sender: TObject;
  var PrintIt: Boolean);
begin
    if DMRel.QueryRFatura.FieldByName('TELEMONITORADO').AsInteger = -1 then
        inc(QuantTele)
    else
        inc(QuantRast);
end;

procedure TFormRFatura4.RLReport1BeforePrint(Sender: TObject;
  var PrintIt: Boolean);
begin
    QuantRast := 0;
    QuantTele := 0;
    TotalTempo := 0;
    TotalPeso := 0;
end;

procedure TFormRFatura4.RLLabel27BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := '';
    with DMRel.QueryRFaturaRastreador do
    begin
        ParamByName('pcodfatura').AsInteger := CodFatura;
        open;
        first;
        while not DMRel.QueryRFaturaRastreador.eof do
        begin
            Text := Text + FieldByName('descricao').AsString + ' '+ FieldByName('quantidade').AsString +'   ';
            next;
        end;
        close;
    end;
end;

procedure TFormRFatura4.RLDBText22BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    TotalPeso := TotalPeso + DMRel.dsRelat.DataSet.FieldByName('PESO').AsFloat;
end;

procedure TFormRFatura4.RLDBText23BeforePrint(Sender: TObject; var Text: string;
  var PrintIt: Boolean);
begin
    Text := Text +' '+ DMRel.dsRelat.DataSet.FieldByName('HORA').AsString;
end;

procedure TFormRFatura4.RLDBText26BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    TotalTempo := TotalTempo + DMRel.dsRelat.DataSet.FieldByName('TEMPO').AsInteger;
    Text := TimeToDaysTime(DMRel.dsRelat.DataSet.FieldByName('TEMPO').AsInteger);
end;

procedure TFormRFatura4.RLDBResult1BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := IntToStr(TotalTempo);
    Text := Text + ' Horas';
end;

procedure TFormRFatura4.RLDBResult4BeforePrint(Sender: TObject;
  var Text: String; var PrintIt: Boolean);
begin
    Text := FloatToStr(TotalPeso/1000);
end;

end.
